<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="author" content="order by dede58.com"/>
    <title>个人信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="common/bootstrap/css/bootstrap.css" media="all">
    <link rel="stylesheet" type="text/css" href="common/global.css" media="all">
    <link rel="stylesheet" type="text/css" href="css/personal.css" media="all">
    <script type="text/javascript" src="js/jquery2.js"></script>
</head>
<body>
<section class="layui-larry-box">
    <div class="larry-personal">
        <header class="larry-personal-tit">
            <span>添加部门</span>
        </header><!-- /header -->
        <div class="larry-personal-body clearfix">
            <form class="layui-form col-lg-5" id="saveUser">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="uname" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户密码</label>
                    <div class="layui-input-block">
                        <input type="text" name="pass" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户状态</label>
                    <div class="layui-input-block">
                        <input type="text" name="isStatus" value="Y" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <input type="text" name="remark" autocomplete="off" class="layui-input" placeholder="输入负责人名称">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">对应员工</label>
                    <div class="layui-input-block">
                        <select class="layui-select" name="empId" id="sel" style="display: block; width: 170px"
                                lay-filter="aihao">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item" hidden>
                    <label class="layui-form-label">对应角色</label>
                    <div class="layui-input-block">
                        <select class="layui-select" name="roleId" id="showSel" style="display: block; width: 170px"
                                lay-filter="aihao">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
            </form>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" id="sub">立即提交</button>
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript" src="common/layui/layui.js"></script>
<script>
    $(function () {
        $.ajax({
            type: "get",
            url: "akun/qea",
            dataType: "json",
            success: function (data) {
                // console.log( typeof data);
                $.each(data, function (index, da) {
                    var options = $("<option value='" + da.id + "'>" + da.empname + "</option>");
                    $("#sel").append(options);
                });
            },
            error: function () {
                window.location.href = "404.jsp";
            }
        });

        $.ajax({
            type: "get",
            url: "sys/querySysRoleAll",
            dataType: "json",
            success: function (data) {
                // console.log( typeof data);
                $.each(data, function (index, da) {
                    var options = $("<option value='" + da.id + "' name='id'>" + da.roleName + "</option>");
                    $("#showSel").append(options);
                });
                fun();
            },
            error: function () {
                window.location.href = "404.jsp";
            }
        });

        function fun() {
            var ids = $("[name='id']");
            for (var i = 0; i < ids.length; i++) {
                if (ids[i].innerHTML == "普通用户") {
                    $(ids[i]).prop("selected", true);
                }
            }
        }

        $("#sub").on("click", function () {
            $.ajax({
                type: "get",
                url: "${pageContext.request.contextPath}/user/saveUser",
                data: $("#saveUser").serialize(),
                success: function () {
                    window.location.href = "showUser.jsp";
                },
                error: function (data) {
                    window.location.href = "404.jsp";
                }
            });
        });
    })
</script>
</body>
</html>